"use strict";
/// <reference types="../../../../../node_modules/.vue-global-types/vue_3.5_false.d.ts" />
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var vue_1 = require("vue");
var howler_1 = require("howler");
var props = (0, vue_1.defineProps)();
var howl = (0, vue_1.ref)(null);
var isPlaying = (0, vue_1.ref)(false);
var progress = (0, vue_1.ref)(0);
var currentTime = (0, vue_1.ref)(0);
var duration = (0, vue_1.ref)(0);
var isSupported = (0, vue_1.ref)(true);
// 添加音频格式支持检查
var supportedFormats = ['mp3', 'wav', 'm4r', 'ogg', 'flac', 'aac'];
var initAudio = function () {
    if (howl.value) {
        howl.value.unload();
    }
    howl.value = new howler_1.Howl({
        src: [props.filePath],
        html5: true,
        format: supportedFormats, // 添加格式支持
        onplay: function () {
            isPlaying.value = true;
            updateProgress();
        },
        onpause: function () {
            isPlaying.value = false;
        },
        onload: function () {
            var _a;
            duration.value = ((_a = howl.value) === null || _a === void 0 ? void 0 : _a.duration()) || 0;
        },
        onstop: function () {
            isPlaying.value = false;
        },
        onloaderror: function (id, error) {
            // console.error('Audio load error:', id, error)
            // 可以在这里添加错误提示
            isSupported.value = false;
        },
        onplayerror: function (id, error) {
            // console.error('Audio play error:', error)
            // 可以在这里添加错误提示
            isSupported.value = false;
        }
    });
};
var togglePlay = function () {
    if (!howl.value)
        return;
    if (howl.value.playing()) {
        howl.value.pause();
    }
    else {
        howl.value.play();
    }
};
var seek = function (event) {
    if (!howl.value)
        return;
    var target = event.target;
    var time = (Number(target.value) / 100) * duration.value;
    howl.value.seek(time);
};
var updateProgress = function () {
    if (!howl.value || !isPlaying.value)
        return;
    requestAnimationFrame(updateProgress);
    currentTime.value = howl.value.seek();
    progress.value = (currentTime.value / duration.value) * 100;
};
var formatTime = function (time) {
    var minutes = Math.floor(time / 60);
    var seconds = Math.floor(time % 60);
    return "".concat(minutes, ":").concat(seconds.toString().padStart(2, '0'));
};
// 监听 audioUrl 变化
(0, vue_1.watch)(function () { return props.filePath; }, function () {
    initAudio();
});
(0, vue_1.onMounted)(function () {
    initAudio();
});
// 添加组件卸载时的清理
(0, vue_1.onUnmounted)(function () {
    if (howl.value) {
        howl.value.unload();
    }
}); /* PartiallyEnd: #3632/scriptSetup.vue */
function __VLS_template() {
    var __VLS_ctx = {};
    var __VLS_components;
    var __VLS_directives;
    // CSS variable injection 
    // CSS variable injection end 
    __VLS_elementAsFunction(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)(__assign({ class: ("audio-player-container") }));
    __VLS_elementAsFunction(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)(__assign({ class: ("audio-player") }));
    __VLS_elementAsFunction(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)(__assign({ class: ("progress-bar") }));
    __VLS_elementAsFunction(__VLS_intrinsicElements.input, __VLS_intrinsicElements.input)(__assign(__assign({ onInput: (__VLS_ctx.seek) }, { type: ("range"), value: ((__VLS_ctx.progress)), min: ("0"), max: ("100") }), { class: ("progress") }));
    __VLS_elementAsFunction(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)(__assign({ class: ("time") }));
    __VLS_elementAsFunction(__VLS_intrinsicElements.span, __VLS_intrinsicElements.span)({});
    (__VLS_ctx.formatTime(__VLS_ctx.currentTime));
    __VLS_elementAsFunction(__VLS_intrinsicElements.span, __VLS_intrinsicElements.span)({});
    (__VLS_ctx.formatTime(__VLS_ctx.duration));
    if (!__VLS_ctx.isSupported) {
        __VLS_elementAsFunction(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)(__assign({ class: ("loading-hint") }));
    }
    __VLS_elementAsFunction(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)(__assign({ class: ("audio-player-button") }));
    __VLS_elementAsFunction(__VLS_intrinsicElements.button, __VLS_intrinsicElements.button)(__assign(__assign({ onClick: (__VLS_ctx.togglePlay) }, { class: ("play-btn") }), { disabled: ((!__VLS_ctx.isSupported)) }));
    (__VLS_ctx.isPlaying ? '暂停' : '播放');
    ['audio-player-container', 'audio-player', 'progress-bar', 'progress', 'time', 'loading-hint', 'audio-player-button', 'play-btn',];
    var __VLS_slots;
    var $slots;
    var __VLS_inheritedAttrs;
    var $attrs;
    var __VLS_refs = {};
    var $refs;
    var $el;
    return {
        attrs: {},
        slots: __VLS_slots,
        refs: $refs,
        rootEl: $el,
    };
}
;
var __VLS_self = (await Promise.resolve().then(function () { return require('vue'); })).defineComponent({
    setup: function () {
        return {
            isPlaying: isPlaying,
            progress: progress,
            currentTime: currentTime,
            duration: duration,
            isSupported: isSupported,
            togglePlay: togglePlay,
            seek: seek,
            formatTime: formatTime,
        };
    },
    __typeProps: {},
});
exports.default = (await Promise.resolve().then(function () { return require('vue'); })).defineComponent({
    setup: function () {
        return {};
    },
    __typeProps: {},
    __typeEl: {},
});
; /* PartiallyEnd: #4569/main.vue */
